/**
 * @author  : ZhiBing.Li
 * @date    : 2013-10-15下午01:27:50
 */
package flexcomm.controls.checkboxdg
{
	import mx.collections.ArrayCollection;
	import mx.core.ClassFactory;
	
	import spark.components.DataGrid;
	import spark.components.gridClasses.GridColumn;
	
	public class CheckBoxDataGrid extends DataGrid
	{
		//存放checkBox选中数据源
		private var _dataSource:ArrayCollection = null;
		//设置表头复选框
		//设置第一列表头
		//设置表身复选框
		
		public function CheckBoxDataGrid()
		{
			super();
			_dataSource = new ArrayCollection();
		}
		
		override protected function createChildren():void
		{
			super.createChildren();
			
			if(this.columns)
			{
				//新建表格一列容器引用
				var gridColumn:GridColumn = new GridColumn();
				//设置表格宽度
				gridColumn.width = 30;
				//设置表头类引用
				var classRef:ClassFactory = new ClassFactory(flexcomm.controls.checkboxdg.CheckBoxHeader);
				//将自定义表头赋值给表格表头呈示器
				gridColumn.headerRenderer = classRef;
				//设置表身类引用
				classRef = new ClassFactory(flexcomm.controls.checkboxdg.CheckBoxGrid);
				//将自定义表身赋值给表格表身呈示器
				gridColumn.itemRenderer = classRef;
				//将自定义复选框添加到表格中
				this.columns.addItemAt(gridColumn,0);
			}
		}
		
		//增加选择的状态数据
		public function addToSelected(item:Object):void
		{
			if(dataSource.getItemIndex(item) < 0)
			{
				dataSource.addItem(item);
			}
		}
		
		//删除选择的状态数据
		public function removeToSelected(item:Object):void
		{
			if(dataSource.getItemIndex(item) > -1)
			{
				dataSource.removeItemAt(dataSource.getItemIndex(item));
			}
		}
		
		//判断是否是选择状态
		public function isSelected(item:Object):Boolean
		{
			if(dataSource.getItemIndex(item) < 0)
			{
				return false;
			}
			else
			{
				return true;
			}
		}
		
		//返回checkBox选中的数据
		public function get dataSource():ArrayCollection
		{
			return this._dataSource;
		}
	}
}